using UnityEngine;
using System.Collections;

//change speed according
public class MoveByCurveOnUpdate : CharacterAction
{
	public float forwardSpeed = 0;
    public float upSpeed = 0;
    public float rightSpeed = 0;

	//[HideInInspector]
	public AnimationCurve movementForward = new AnimationCurve();

	//[HideInInspector]
	public AnimationCurve movementUp = new AnimationCurve();

	//[HideInInspector]
	public AnimationCurve movementRight = new AnimationCurve();

	// time at 60fps frames
	public override void OnFrameUpdate (Character.FrameUpdate arg)
	{
		Character character = arg.character;
		Vector3 velocityZ = character.transformRef.forward;
		Vector3 velocityY = character.transformRef.up;
		Vector3 velocityX = character.transformRef.right;

		float time = character.curFrameTime / character.curState.duration;
		float nextTime = (character.curFrameTime + Time.fixedDeltaTime) / character.curState.duration;

		float newSpeedZ = movementForward.Evaluate(nextTime);
        float newSpeedY = movementUp.Evaluate(nextTime);
        float newSpeedX = movementRight.Evaluate(nextTime);

        velocityZ *= newSpeedZ  * forwardSpeed;
        velocityY *= newSpeedY  * upSpeed;
        velocityX *= newSpeedX  * rightSpeed;

		character.rigidbodyRef.velocity = velocityZ + velocityY + velocityX;
	}
}

